const Koa = require('koa')
const Router = require('koa-router')
const views = require('koa-views')
const static = require('koa-static')
const koaBody = require('koa-body')
let app = new Koa()
let router = new Router()
app.use(koaBody())
app.use(views(__dirname + '/views'))
app.use(static(__dirname + '/static'))
router.get('/index', async ctx => {
    await ctx.render('index.html')
})
router.get('/product', async ctx => {
    await ctx.render('product.html')
})
router.get('/getdata', ctx => {
    //接收get传递的参数
    let data = ctx.query
    ctx.body = data
})
router.post('/postdata', ctx => {
    console.log(ctx.request.body);
    ctx.body = ctx.request.body
})
app.use(router.routes())
app.listen(8888)